package 删除子数组的最大得分1695;

import java.util.HashSet;

public class Solution {
    public int maximumUniqueSubarray(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        int left = 0;
        int right = 0;
        int max = 0;
        int sum = 0;
        while (right < nums.length) {
            if (set.contains(nums[right])) {
                set.remove(nums[left]);
                sum -= nums[left];
                left++;
            }else {
                set.add(nums[right]);
                sum += nums[right];
                max = Math.max(max, sum);
                right++;
            }
        }
        return max;
    }
}
